﻿Public Class u_XuatNguyenLieu
    Private Sub LoadData()
        Dim px As New PhieuXuatBUS
        dvgXK.DataSource = px.GetPhieuXuat
        Dim nhom As New NhomBUS
        cbxDonVi.DataSource = nhom.GetNhomNL
        cbxDonVi.DisplayMember = "TenNhomNL"
        cbxDonVi.ValueMember = "MaNhomNL"
        cbxDonVi.SelectedIndex = 0
        Dim nv As New NhanVienBUS
        cbxTenNV.DataSource = nv.GetNhanVien
        cbxTenNV.DisplayMember = "TenNV"
        cbxTenNV.ValueMember = "MaNV"
        cbxTenNV.SelectedIndex = 0
    End Sub

    Private Sub u_XuatNguyenLieu_Load(sender As Object, e As EventArgs) Handles MyBase.Load
        LoadData()
    End Sub

    Private Sub btnThem_Click(sender As Object, e As EventArgs) Handles btnThem.Click
        Dim newPX As New PhieuXuatDTO
        newPX.MaNL = txtMaNL.Text
        newPX.TenNL = txtTenNL.Text
        newPX.NgayXuat = ThoiGian.Value
        newPX.MaNV = cbxTenNV.SelectedIndex
        newPX.DonVi = cbxDonVi.SelectedIndex
        newPX.SoLuong = txtSoLuong.Text
        newPX.KhoiLuong = txtKhoiLuong.Text
        newPX.DonGia = txtDonGia.Text
        Dim pxBUS As New PhieuXuatBUS
        pxBUS.AddPhieuXuat(newPX)
        LoadData()
    End Sub

    Private Sub btnXoa_Click(sender As Object, e As EventArgs) Handles btnXoa.Click
        Dim delPX As New PhieuXuatDTO
        delPX.MaNL = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "MaNL")
        Dim PXBUS As New PhieuXuatBUS
        PXBUS.DelPhieuXuat(delPX)
        LoadData()
    End Sub

    
    Private Sub dgvXK_FocusedRowChanged(sender As Object, e As DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs) Handles dgvXK.FocusedRowChanged
        txtMaNL.Text = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "MaNL")
        ThoiGian.Value = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "NgayXuat")
        txtTenNL.Text = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "TenNL")
        cbxDonVi.SelectedValue = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "DonVi")
        txtSoLuong.Text = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "SoLuong")
        txtKhoiLuong.Text = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "KhoiLuong")
        txtDonGia.Text = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "DonGia")
        cbxTenNV.SelectedValue = dgvXK.GetRowCellValue(dgvXK.FocusedRowHandle, "MaNV")
    End Sub
End Class
